package com.example.springboot_06_blog.controller;

import com.example.springboot_06_blog.mapper.UserMapper;
import com.example.springboot_06_blog.pojo.User;
import com.example.springboot_06_blog.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @auther cangshufeilun
 * @date 2022/4/1 17:00
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService iUserService;

    @GetMapping("/")
    public String index()
    {
        return "user/index";
    }

    @GetMapping("/login")
    public String login(){
        return "user/login";
    }

    @GetMapping("/loginchk")
    public String loginchk(String username, String password, HttpSession session){
     User user=iUserService.login(username,password);
        if(user!=null)
        {
            session.setAttribute("user",user);
            return "redirect:/user/";
        }
        else
        {
            // 跳回登录页
            return "redirect:/user/login";
        }
    }

}
